#include "time.h"
#include "stm32f10x_tim.h"
#include "usart.h"
void TIME_Init(void)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);

	TIM_TimeBaseInitStructure.TIM_Period = TIM3_arr;
	TIM_TimeBaseInitStructure.TIM_Prescaler=TIM3_psk; 
	TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
	TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
	TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
	TIM_Cmd(TIM3,DISABLE);
}

void Tim3_delay_ms(uint8_t ms)
{
	if(ms > 65)
	{
		printf("time6 error2\r\n");
		ms =65;
	}
	TIM_SetCounter(TIM3,0);
	TIM_Cmd(TIM3,ENABLE);
	while((ms*1000) > TIM_GetCounter(TIM3))
	{
	}
	TIM_Cmd(TIM3,DISABLE);
}

void Tim3_delay_us(uint16_t us)
{
	if(us>65535)
	{
		printf("time6 error1\r\n");
		us = 65535;
	}
	TIM_SetCounter(TIM3,0);
	TIM_Cmd(TIM3,ENABLE);
	while(us > TIM_GetCounter(TIM3))
	{
	}
	TIM_Cmd(TIM3,DISABLE);
}
